# encoding=utf-8
import sys

reload(sys)
sys.setdefaultencoding('utf-8')
from Configure import Attribute as att
def topicAddMore(dr,view):
    '''话题加载更多功能'''
    # 坐标# 获取元素的宽和高以及坐标点，是左上方的坐标点
    xForView = view.location_once_scrolled_into_view['x']
    yForView = view.location_once_scrolled_into_view['y']
    # 宽高
    viewWidth = view.size["width"]
    viewHight = view.size["height"]
    # 计算控件结束坐标
    endX = xForView + viewWidth
    endY = viewHight + yForView
    # 计算中间坐标点
    centerX = (endX + xForView) / 2
    centerY = (endY + yForView) / 2
    upOrdown = 'down'
    if upOrdown == 'up':
        dr.swipe(centerX, centerY, centerX, centerY + viewHight / 2, 500)
    elif upOrdown == 'down':
        isContinue = True
        while isContinue:
            topicTexts = dr.find_elements_by_id(att.homeStory_topic_topicText_id)
            for topicText in topicTexts:
                if topicText.text == u'#幼师摄影大赛#':
                    isContinue = False
                    topicText.click()
                    break
            if isContinue:
                if u'没有更多数据了' in dr.page_source:
                    isContinue = False
                dr.swipe(centerX, centerY, centerX, centerY - viewHight / 2, 500)
                view = dr.find_element_by_id(att.homeStory_topic_mainArea_id)
    else:
        raise ValueError("传入错误的值，应该是up或者down进行上拉下拉操作")